package com.study.ext;

import java.util.List;

/**
 * @Author tanglingyu
 * @Date: 2021/06/06/ 13:25
 * @Description
 */
public abstract class AbstractStrategy implements StrategyInterface {

  /**
   * 通用业务逻辑处理
   */
  @Override
  public void deal() {
    //初始化逻辑调用对象
    BusinessApply businessApply = initBusinessApply();
    List<ProcessorInterface> processors = getProcessors();
    for (int i = 0; i < processors.size(); i++) {
      if (processors.get(i).isMatches()) {
        //处理器前置处理
        processors.get(i).beforePostProcessor();
      }
    }
    //核心业务逻辑处理
    businessApply.doRemote();
    for (int i = processors.size() - 1; i >= 0; i--) {
      if (processors.get(i).isMatches()) {
        //处理器后置处理
        processors.get(i).afterPostProcessor();
      }
    }
  }

  //初始化逻辑调用对象(子类实现)
  protected abstract BusinessApply initBusinessApply();
}
